package com.chengen.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.chengen.bean.Street;
import com.chengen.dao.StreetDao;
import com.chengen.dao.impl.StreetDaoImpl;
import com.fasterxml.jackson.databind.ObjectMapper;

@WebServlet("/street")
public class StreetServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	StreetDao streetDao = new StreetDaoImpl();
	ObjectMapper obm = new ObjectMapper();

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String parameter = request.getParameter("id");
		List<Street> findAll = streetDao.findAll(Integer.parseInt(parameter));
		response.setContentType("application/json;charset=utf-8");
		String json = obm.writeValueAsString(findAll);
		System.out.println(json);
		response.getWriter().println(json);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
